package C;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.regex.Pattern;

public class C38 {
    static Pattern p = Pattern.compile("(([01][0-9])|([2][0-3]))[0-5][0-9]");

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(":");
        Character[] arr = new Character[4];
        arr[0] = s[0].charAt(0);
        arr[1] = s[0].charAt(1);
        arr[2] = s[1].charAt(0);
        arr[3] = s[1].charAt(1);
        ArrayList<String> res = new ArrayList<>();
        dfs(arr, new LinkedList<>(), res);
        System.out.println(res);
//        res.sort(String::compareTo);
        res.sort((a,b)->a.compareTo(b));
        System.out.println(res);
        int index = res.indexOf(s[0]+s[1]);
        System.out.println(index);
        System.out.println(res.get(index));
        index = (index+1)%res.size();
        System.out.println(index);
        System.out.println(res.get(index));
    }


    public static void dfs (Character[] arr,LinkedList<Character> path,ArrayList<String> res) {
//        System.out.println(Arrays.toString(arr));
        if (path.size()==4) {
            StringBuffer sb = new StringBuffer();
            for (Character c:path) sb.append(c);
            String timeStr = sb.toString();


            if (p.matcher(timeStr).find() && !res.contains(timeStr)) {
                res.add(timeStr);
            }
            return ;
        }
        for (Character c:arr) {
//            System.out.print(c);
            path.add(c);
            dfs(arr,path,res);
            path.removeLast();
        }
    }
}
